import {getFimvcsHome} from "@/api/api.js";
import {dropSort} from '@/sever/utils';
export const sliderInit = {
    data() {
        return {
            pageChildList:[],
            pathChildId:"",
            src:"",
        }
    },
    methods: {
        init(){
            this.pageChildList = [];
            let path = this.$route.path;
            let ruleList = this.$store.state.ruleList;
            for(let i = 0; i< ruleList.length;i++){
                if(ruleList[i].children && ruleList[i].children.length >0){
                    for(let j = 0; j < ruleList[i].children.length ; j++) {
                        if(path == ruleList[i].children[j].url){
                            this.$store.commit("setModalChildPage", ruleList[i].children[j].children);
                            break;
                        } else {
                            if(ruleList[i].children[j].children && ruleList[i].children[j].children.length > 0) {
                                for(let s = 0; s < ruleList[i].children[j].children.length; s++){
                                    if(path == ruleList[i].children[j].children[s].url){
                                        this.$store.commit("setModalChildPage", ruleList[i].children[j].children);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.$store.state.ModalChildPage.forEach(v=>{
                this.pageChildList.push(v)
            })
            this.pageChildList = dropSort(this.pageChildList,'index');
            //去重
            let newobj = {}; 
            this.pageChildList = this.pageChildList .reduce((preVal, curVal) => {
                newobj[curVal.id] ? '' : newobj[curVal.id] = preVal.push(curVal); 
                return preVal 
            }, [])
            if(localStorage.getItem("pathChildId")){
                this.pathChildId = localStorage.getItem("pathChildId")
            } else {
               this.pathChildId = this.pageChildList[0].id;
            }
        },
        getChildPath(item){ 
            if(this.$route.path===item.url){
                return
            }
            if(item.code == "fim/vcs") {
                window.open(this.src)
            } else {
                this.pathChildId = item.id;
                localStorage.setItem("pathChildId", item.id);
                this.$router.push({ path: item.url });
            }
        },
        geturl(){
            getFimvcsHome().then(res=>{
                if(res.code == 200) {
                    this.src = res.data;
                }
            }).catch(error=>{
                console.log(error)
            })
        },
    },
    computed: {
        getsliderId() {
            return this.$store.state.sliderId;
        }
    },
    // watch: {
    //     getsliderId(val, oldVal) {
    //         console.log(val)
    //     }
    // },
}
